//
//  UIButton.swift
//  Weibo
//
//  Created by 孙成宇 on 15/11/29.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit


extension UIButton {


    convenience init(title: String,backImage: String?,color: UIColor,fontSize: CGFloat = 15,isNeedHighlighted: Bool = false,imageName: String? = nil ){
        //便利的构造方法 可以访问self对象
        self.init()
        
        setTitle(title, forState: .Normal)
        if backImage != nil{
        
        
        setBackgroundImage(UIImage(named: backImage!), forState: .Normal)
        if isNeedHighlighted  {
            setBackgroundImage(UIImage(named: backImage! + "_highlighted"), forState: .Normal)
        }
        }
        
        if imageName != nil {
       
            setImage(UIImage(named: imageName!), forState: .Normal)
        
        }
        
        setTitleColor(color, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        
        sizeToFit()

    }

    convenience init(imageName: String?, backImage: String){
        //便利的构造方法 可以访问self对象
        self.init()
        setBackgroundImage(UIImage(named: backImage), forState: .Normal)
        setBackgroundImage(UIImage(named: backImage + "_highlighted"), forState: .Highlighted)

        if imageName != nil {

            setImage(UIImage(named: imageName!), forState: .Normal)
            setImage(UIImage(named: imageName! + "_highlighted"), forState: .Highlighted)

        }


        sizeToFit()
    }

    


}